package counter;

import redis.clients.jedis.Jedis;

public class RedisCounterExample {
    private static final String HOST = "localhost";
    private static final int PORT = 6379;
    private static final String KEY = "page_view";

    public static void main(String[] args) {
        // 连接到Redis服务器
        Jedis jedis = new Jedis(HOST, PORT);

        // 初始化计数器
        jedis.set(KEY, "0");

        // 模拟访问网页
        for (int i = 0; i < 10; i++) {
            // 计数器加1
            long count = jedis.incr(KEY);
            // 输出当前浏览量
            System.out.println("Page views: " + count);
        }
        // 关闭连接
        jedis.close();
    }
}

